package game.players.user;

import game.players.SoccerPlayer;
import game.players.states.WithBall;
import game.players.user.running.WithBallStationaryRunningUser;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.events.constants.Key;

public abstract class WithBallUser extends WithBall {
	
	public WithBallUser(SoccerPlayer player) {
		super(player);
		this.setTeammates(this.getPlayer().getScene().getTeammates());
	}

	@Override
	public void update(DeltaState deltaState) {
		
		if (deltaState.isKeyBeingHold(Key.SHIFT))
			this.getPlayer().setState(new WithBallStationaryRunningUser(this.getPlayer()));
		
		//TIRO AL ARCO
		if(deltaState.isKeyPressed(Key.Z)) {
			double arcHeight = this.getPlayer().getRivalArc().getAppearance().getHeight();
			if(deltaState.isKeyBeingHold(Key.UP))
				this.getPlayer().setState(new ShootingUserPlayer(this.getPlayer(), arcHeight / 3 - this.getPlayer().getY()));
			else
				if (deltaState.isKeyBeingHold(Key.DOWN))
					this.getPlayer().setState(new ShootingUserPlayer(this.getPlayer(), arcHeight / 3 * 2 - this.getPlayer().getY()));
				else
					this.getPlayer().setState(new ShootingUserPlayer(this.getPlayer(), arcHeight / 2 - this.getPlayer().getY()));
		}
		
		//PASE
		if(deltaState.isKeyPressed(Key.X))
			if(deltaState.isKeyBeingHold(Key.UP))
				this.getPlayer().setState(new PassingUserPlayer(this.getPlayer(), this.getUpClosestMate()));
			else
				if(deltaState.isKeyBeingHold(Key.DOWN))
					this.getPlayer().setState(new PassingUserPlayer(this.getPlayer(), this.getDownClosestMate()));
				else
					if(deltaState.isKeyBeingHold(Key.LEFT))
						this.getPlayer().setState(new PassingUserPlayer(this.getPlayer(), this.getLeftClosestMate()));
					else
						if(deltaState.isKeyBeingHold(Key.RIGHT))
							this.getPlayer().setState(new PassingUserPlayer(this.getPlayer(), this.getRightClosestMate()));
						else
							this.getPlayer().setState(new PassingUserPlayer(this.getPlayer(), this.getClosestMate()));
	}
}
